package com.zhangyongyi.carhome.adapter.Forum.featureddaily.halloffame;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zhangyongyi.carhome.R;
import com.zhangyongyi.carhome.entity.greendao.ForumList;

import java.util.List;

/**
 * Created by dllo on 16/1/21.
 */
public class HallOfFameAdapter extends RecyclerView.Adapter<HallOfFameAdapter.MyViewHolder> {

    private List<ForumList> forumLists;

    public void addData(List<ForumList> datas) {
        forumLists = datas;
        notifyDataSetChanged();

    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
        View view = inflater.inflate(R.layout.item_holl_of_fame, null);

        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        if (forumLists != null && forumLists.size() > 0) {
            ForumList forumList = forumLists.get(position);
            holder.title.setText(forumList.getTitle());
            holder.replycount.setText(String.valueOf(forumList.getReplycounts()));
            holder.bbsname.setText(forumList.getBbsname());
        }
    }

    @Override
    public int getItemCount() {
        return forumLists != null && forumLists.size() > 0 ? forumLists.size() : 0;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView bbsname, replycount, title;

        public MyViewHolder(View itemView) {
            super(itemView);
            bbsname = (TextView) itemView.findViewById(R.id.tv_bbsname_holl_of_fame_item);
            replycount = (TextView) itemView.findViewById(R.id.tv_replycount_holl_of_fame_item);
            title = (TextView) itemView.findViewById(R.id.tv_title_holl_of_fame_item);
        }
    }
}
